package cn.dai;

import java.util.Scanner;

public class GuessingGame {

    private static Gamer bot;
    private static Gamer player;
    private static Scanner input = new Scanner(System.in);
    private static int round = 0;

    public static void gameInit(){
        bot = new Gamer();
        player = new Gamer();
        System.out.println("----------------欢迎进入游戏世界---------------------");
        System.out.println("\n");
        System.out.println("\t\t*******************\t\t");
        System.out.println("\t\t****\t猜拳,开始\t***\t\t");
        System.out.println("\t\t*******************\t\t");
        System.out.println("出拳规则:1.剪刀2.石头3.布");
        chooseBotName();
        chooseMyName();
        System.out.println(player.getName() + " VS " + bot.getName());
    }

    private static void chooseBotName(){
        System.out.println("请选择对方角色(1:刘备2:孙权3:曹操)");
        int select  = input.nextInt();
        String botName = null;
        switch (select) {
            case 1:
                botName = "刘备";
                System.out.println("你选择了刘备对战");
                break;
            case 2:
                botName = "孙权";
                System.out.println("你选择了孙权对战");
                break;
            case 3:
                botName = "曹操";
                System.out.println("你选择了曹操对战");
                break;
        }
        bot.setName(botName);
    }

    private static void chooseMyName(){
        System.out.println("请输入你的姓名:");
        player.setName(input.next());
    }

    public static void startGame(){
        System.out.println("\n要开始码?(y/n)");
        String answer = input.next();

        while ("y".equalsIgnoreCase(answer)) {
            round ++;
            judging();
            System.out.println("\n是否开始下一轮(y/n):");
            answer = input.next();
        }
    }

    public static void credit(){
        System.out.println("------------------------------------------");
        System.out.println(player.getName() + "VS" + bot.getName());
        System.out.println("对战次数:" + round);
        System.out.println("姓名\t\t得分");
        System.out.println(player.getName() + "\t\t" + player.getScore());
        System.out.println(bot.getName() + "\t\t" + bot.getScore());
        if (bot.getScore() < player.getScore()) {
            System.out.println("结果:恭喜");
        } else if (bot.getScore() == player.getScore()) {
            System.out.println("结果:还好,平局");
        } else {
            System.out.println("结果:呵呵,笨笨,下次加油!");
        }
        System.out.println("------------------------------------------");
    }

    private static void judging(){
        System.out.println(player.getName() + " 请出拳：[ 1.剪刀 2.石头 3.布子 ]");
        String playerFist = player.fist(input.nextInt());
        System.out.println(player.getName() + " 出拳：" + playerFist);

        System.out.println("- - - - - - -");

        System.out.println(bot.getName() + " 请出拳：[ 1.剪刀 2.石头 3.布子 ]");
        String botFist = bot.fist();
        System.out.println(bot.getName() + " 出拳：" + botFist);

        if (
                ("石头".equals(playerFist) && "剪刀".equals(botFist)) ||
                        ("剪刀".equals(playerFist) && "布子".equals(botFist)) ||
                        ("布子".equals(playerFist) && "石头".equals(botFist))
        ){
            System.out.println("你赢了");
            player.setScore(player.getScore() + 1);
        } else if (playerFist.equals(botFist)){
            System.out.println("平局");
        } else {
            System.out.println("你输了");
            bot.setScore(bot.getScore() + 1);
        }

    }
}
